package cn.edu.swu.lxy.rolems.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import cn.edu.swu.lxy.rolems.R
import cn.edu.swu.lxy.rolems.Role
import cn.edu.swu.lxy.rolems.activity.MainActivity
import cn.edu.swu.lxy.rolems.adapter.RolesAdapter


class RolesFragment : Fragment() {
    private val itemList = ArrayList<Role>()
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
        val view = View.inflate(activity, R.layout.fragment_roles, null)
        initItems()
        val layoutManager = LinearLayoutManager(activity)
        layoutManager.orientation = LinearLayoutManager.VERTICAL
        val recyclerView = view.findViewById<RecyclerView>(R.id.recyclerView)
        recyclerView.layoutManager = layoutManager
        val adapter = RolesAdapter(activity as MainActivity, itemList)
        recyclerView.adapter = adapter
        return view
    }
    private fun initItems() {
        repeat(1) {
            itemList.add(Role("胡桃", R.drawable.r1, "火", "要来往生堂嘛"))
            itemList.add(Role("甘雨", R.drawable.r2, "冰", "工作还没做完"))
            itemList.add(Role("绮良良", R.drawable.r3, "草", "送快递喽"))
            itemList.add(Role("纳西妲", R.drawable.r4, "草", "散兵是我儿"))
            itemList.add(Role("八重神子", R.drawable.r5, "雷", "小可爱是你吗"))
            itemList.add(Role("妮露", R.drawable.r6, "水", "花神诞日来了么"))
        }
    }
}